﻿using AutoMapper;
using MediatR;
using SmartCity.ProcessEngine.API.Write.Application.Commands.FormNodes;
using SmartCity.ProcessEngine.Domain;
using SmartCity.ProcessEngine.Errorcode;
using SmartCity.ProcessEngine.Infrastructure.Interfaces;

namespace SmartCity.ProcessEngine.API.Write.Application.CommandHandlers.FormNodes
{
    /// <summary>
    /// 处理
    /// </summary>
    public class UpdateNodeCommandHandler:IRequestHandler<UpdateNodeCommand,ApiResult<int>>
    {
        private readonly IBaseRepository<WF_Node> nodeRep;
        private readonly IMapper mapper;

        public UpdateNodeCommandHandler(IBaseRepository<WF_Node> nodeRep,IMapper mapper)
        {
            this.nodeRep = nodeRep;
            this.mapper = mapper;
        }
        /// <summary>
        /// 修改处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<int>> Handle(UpdateNodeCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.code = ApiEnum.UpdateSuccess;
            result.message = "修改成功";

            WF_Node entity = mapper.Map<WF_Node>(request);
            //entity.NodeNo = request.NodeNo;
            //entity.NodeName = request.NodeName;
            //entity.FormNo = request.FormNo;

            var list = await nodeRep.UpdateAsync(entity);
            result.data = list;

            return await Task.FromResult(result);
        }
    }
}
